package com.itheima.controller;

import com.itheima.pojo.Clazz;
import com.itheima.pojo.ClazzQueryParam;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author hu
 * @date 2025/3/4
 */
@RestController
@Slf4j
@RequestMapping("/clazzs")
public class ClazzController {
    @Autowired
    private ClazzService clazzService;

    @GetMapping
    public Result PageList(ClazzQueryParam queryParam) {
        log.info("接受请求参数：{}", queryParam);
        PageResult<Clazz> clazzes = clazzService.page(queryParam);
        return Result.success(clazzes);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable(value = "id") Integer clazzId) {
        log.info("==============接受删除请求参数：{}", clazzId);
        clazzService.deleteById(clazzId);
        return Result.success();
    }

    @PostMapping
    public Result add(@RequestBody Clazz clazz) {
        log.info("==============接受请求参数：{}", clazz);
        clazzService.addClazz(clazz);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result sel(@PathVariable(value = "id") Integer clazzId) {
        log.info("==============接受请求参数：{}", clazzId);
        Clazz clazz = clazzService.selById(clazzId);
        return Result.success(clazz);
    }

    @PutMapping
    public Result update(@RequestBody Clazz clazz) {
        log.info("==============接受请求参数：{}", clazz);
        clazzService.updateById(clazz);
        return Result.success();
    }

    @GetMapping("/list")
    public Result sel() {
        log.info("==============接受请求参数");
        List<Clazz> clazzs = clazzService.sel();
        return Result.success(clazzs);
    }

}
